﻿Public Class FormLogListado

    Private Sub FormLogListado_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        dgLOG.AutoGenerateColumns = False
        fechaInicio.Value = DateTime.Now.AddDays(-5)

        CargarCombos()
        CargarLogs()

        txtDescripcion.Focus()

        Me.WindowState = FormWindowState.Maximized

    End Sub

    Dim classController As New Class_RC_Controller.rc_Mantenimiento()

    'Private m_frmPedido As FrmPedidosN
    'Public Property frmPedido() As FrmPedidosN
    '    Get
    '        Return m_frmPedido
    '    End Get
    '    Set(value As FrmPedidosN)
    '        m_frmPedido = value
    '    End Set
    'End Property

    Private Sub FormPedidosListado_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        
    End Sub

    Private Sub CargarLogs()

        Dim codUsuario As Integer = 0
        If cbxUsuario.Checked Then
            codUsuario = cboUsuario.SelectedValue
        End If

        Dim codFuncion As Integer = 0
        If cbxFuncion.Checked Then
            codFuncion = cboFunciones.SelectedValue
        End If

        Dim dt As New DataTable
        dt = classController.get_Log_All(oiml.dbConn, txtDescripcion.Text, codUsuario, codFuncion, fechaInicio.Value, fechaFin.Value)

        dgLOG.DataSource = dt

        txtDescripcion.Focus()

        If Not classController.MessageError Is Nothing Then
            MessageBox.Show("Error: " & classController.MessageError.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

    End Sub

    Private Sub CargarCombos()
        Dim ds As DataTable
        ds = classController.get_Usuario_All(oiml.dbConn, 0, "", "", "", 0)
        With cboUsuario
            .DataSource = ds
            .DisplayMember = "usuario"
            .ValueMember = "codusuario"
        End With

        Dim dsFunciones As DataTable
        dsFunciones = classController.get_Funciones_All(oiml.dbConn, "")
        With cboFunciones
            .DataSource = dsFunciones
            .DisplayMember = "descripcionFuncion"
            .ValueMember = "codfuncion"
        End With

    End Sub

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnVer_Click(sender As System.Object, e As System.EventArgs)
        Try
            'If dgPedidos.SelectedRows.Count > 0 Then
            '    Dim cod As New Integer
            '    cod = dgPedidos.SelectedRows(0).Cells(0).Value

            '    If frmPedido Is Nothing Then

            '        frmPedido = New FrmPedidosN()
            '        frmPedido.codNota = cod

            '        'If frmClientes.ShowDialog() = Windows.Forms.DialogResult.OK Then
            '        frmPedido.ShowDialog()
            '        CargarNotas()
            '        frmPedido.Dispose()
            '        frmPedido = Nothing
            '        'End If
            '    Else
            '        frmPedido.codNota = cod
            '        frmPedido.ShowDialog()
            '    End If

            'End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(sender As System.Object, e As System.EventArgs) Handles txtBuscar.Click
        CargarLogs()
    End Sub

    Private Sub txtDescripcion_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcion.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarLogs()

        End If
    End Sub

    'Private Sub dgPedidos_DoubleClick(sender As System.Object, e As System.EventArgs) Handles dgPedidos.DoubleClick
    '    btnEditar_Click(sender, e)
    'End Sub

    'Private Sub dgPedidos_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles dgPedidos.KeyDown
    '    If e.KeyCode = Keys.Enter Then
    '        btnEditar_Click(sender, e)
    '    End If

    'End Sub

    'Private m_frmRpts As FormReportes
    'Public Property frmRpts() As FormReportes
    '    Get
    '        Return m_frmRpts
    '    End Get
    '    Set(value As FormReportes)
    '        m_frmRpts = value
    '    End Set
    'End Property

    'Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprimir.Click

    '    txtBuscar_Click(sender, e)

    '    If frmRpts Is Nothing Then
    '        frmRpts = New FormReportes()
    '        'frmRpts.MdiParent = Me
    '        frmRpts.tipo_Reporte = "PEDIDOS"
    '        frmRpts.datos_Reporte = CargarNotasReporte()
    '        frmRpts.ShowDialog()
    '    Else

    '        If Not frmRpts.Visible Then
    '            frmRpts = New FormReportes()
    '            'frmRpts.MdiParent = Me
    '            frmRpts.tipo_Reporte = "PEDIDOS"
    '            frmRpts.datos_Reporte = CargarNotasReporte()
    '            frmRpts.ShowDialog()
    '        Else
    '            frmRpts.tipo_Reporte = "PEDIDOS"
    '            frmRpts.datos_Reporte = CargarNotasReporte()
    '            frmRpts.Select()
    '            frmRpts.Activate()
    '        End If

    '    End If
    'End Sub

    
    Private Sub fechaInicio_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles fechaInicio.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarLogs()

        End If
    End Sub

    Private Sub fechaFin_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles fechaFin.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarLogs()

        End If
    End Sub

    Private Sub cbxUsuario_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles cbxUsuario.CheckedChanged
        CargarLogs()
    End Sub

    Private Sub cbxFuncion_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles cbxFuncion.CheckedChanged
        CargarLogs()
    End Sub
End Class